<?php

/** Include PHPExcel */
require './././libs/PHPExcel.php';


class XLS_Rotate extends PHPExcel
{
	
	

	function Header()
	{
		//$this->getActiveSheet()->setCellValue('J1', "Tanggal Cetak :".date('d-m-Y, g:i a'));
		$this->getActiveSheet()->getStyle('A1:AZ1000')->getFont()->setName('Calibri');
		$this->getActiveSheet()->getStyle('A1')->getFont()->setSize(14);
		$this->getActiveSheet()->getStyle('A1:AZ1')->getFont()->setBold(true);
		$this->getActiveSheet()->getStyle('A2')->getFont()->setSize(9);
		$this->getActiveSheet()->getStyle('A3:AZ1000')->getFont()->setSize(11);
		
	}

	
		
	
	function HeaderAtas1($judul,$par_umum1){
		$this->getActiveSheet()->setCellValue('A1',"$judul");
		//bulan
		$kdbln_awal=$par_umum1['kdbln_awal'];
		$kdbln_akhir=$par_umum1['kdbln_akhir'];
		//tanggal
		$kdtgl_awal=$par_umum1['kdtgl_awal'];
		$kdtgl_akhir=$par_umum1['kdtgl_akhir'];
		
		//var_dump($kdbln_awal);
		//var_dump($kdbln_akhir);
		if(isset($kdtgl_awal) || isset($kdtgl_akhir) || isset($kdbln_awal) || isset($kdbln_akhir)){
			if(isset($kdbln_awal) && isset($kdbln_akhir)){
				if ($kdbln_awal != 'null' && $kdbln_akhir != 'null'){
					if($kdbln_awal=='01'){
						$kdbln_awal1='JANUARI';
					}elseif($kdbln_awal=='02'){
						$kdbln_awal1='FEBRUARI';
					}elseif($kdbln_awal=='03'){
						$kdbln_awal1='MARET';
					}elseif($kdbln_awal=='04'){
						$kdbln_awal1='APRIL';
					}elseif($kdbln_awal=='05'){
						$kdbln_awal1='MEI';
					}elseif($kdbln_awal=='06'){
						$kdbln_awal1='JUNI';
					}elseif($kdbln_awal=='07'){
						$kdbln_awal1='JULI';
					}elseif($kdbln_awal=='08'){
						$kdbln_awal1='AGUSTUS';
					}elseif($kdbln_awal=='09'){
						$kdbln_awal1='SEPTEMBER';
					}elseif($kdbln_awal=='10'){
						$kdbln_awal1='OKTOBER';
					}elseif($kdbln_awal=='11'){
						$kdbln_awal1='NOPEMBER';
					}elseif($kdbln_awal=='12'){
						$kdbln_awal1='DESEMBER';
					}else{
						
					}
					
					if($kdbln_akhir=='01'){
						$kdbln_akhir1='JANUARI';
					}elseif($kdbln_akhir=='02'){
						$kdbln_akhir1='FEBRUARI';
					}elseif($kdbln_akhir=='03'){
						$kdbln_akhir1='MARET';
					}elseif($kdbln_akhir=='04'){
						$kdbln_akhir1='APRIL';
					}elseif($kdbln_akhir=='05'){
						$kdbln_akhir1='MEI';
					}elseif($kdbln_akhir=='06'){
						$kdbln_akhir1='JUNI';
					}elseif($kdbln_akhir=='07'){
						$kdbln_akhir1='JULI';
					}elseif($kdbln_akhir=='08'){
						$kdbln_akhir1='AGUSTUS';
					}elseif($kdbln_akhir=='09'){
						$kdbln_akhir1='SEPTEMBER';
					}elseif($kdbln_akhir=='10'){
						$kdbln_akhir1='OKTOBER';
					}elseif($kdbln_akhir=='11'){
						$kdbln_akhir1='NOPEMBER';
					}elseif($kdbln_akhir=='12'){
						$kdbln_akhir1='DESEMBER';
					}else{
						
					}
					$bulan='PERIODE:' . $kdbln_awal1 . ' s/d ' . $kdbln_akhir1;					
					$this->getActiveSheet()->setCellValue('A2',"$bulan");				
					
				}elseif ($kdbln_awal == 'null' && $kdbln_akhir == 'null') {
					$kdbln_akhir1=date('m');
						if($kdbln_akhir1=='01'){
							$kdbln_akhir1='JANUARI';
						}elseif($kdbln_akhir1=='02'){
							$kdbln_akhir1='FEBRUARI';
						}elseif($kdbln_akhir1=='03'){
							$kdbln_akhir1='MARET';
						}elseif($kdbln_akhir1=='04'){
							$kdbln_akhir1='APRIL';
						}elseif($kdbln_akhir1=='05'){
							$kdbln_akhir1='MEI';
						}elseif($kdbln_akhir1=='06'){
							$kdbln_akhir1='JUNI';
						}elseif($kdbln_akhir1=='07'){
							$kdbln_akhir1='JULI';
						}elseif($kdbln_akhir1=='08'){
							$kdbln_akhir1='AGUSTUS';
						}elseif($kdbln_akhir1=='09'){
							$kdbln_akhir1='SEPTEMBER';
						}elseif($kdbln_akhir1=='10'){
							$kdbln_akhir1='OKTOBER';
						}elseif($kdbln_akhir1=='11'){
							$kdbln_akhir1='NOPEMBER';
						}elseif($kdbln_akhir1=='12'){
							$kdbln_akhir1='DESEMBER';
						}
						$bulan='BULAN:  s/d ' .$kdbln_akhir1.' '. Session::get('ta');					
						$this->getActiveSheet()->setCellValue('A2',"$bulan");
			
				
				}
			}
			if(isset($kdtgl_awal) && isset($kdtgl_akhir)){
				if($kdtgl_awal != 'null' && $kdtgl_akhir != 'null') {
					$thn1 = substr($kdtgl_awal, 6, 4);
					$bln1 = substr($kdtgl_awal, 3, 2);
					$tgl1 = substr($kdtgl_awal, 0, 2);
					$kdtgl_awal = $tgl1 . '-' . $bln1 . '-' . $thn1;
					$thn2 = substr($kdtgl_akhir, 6, 4);
					$bln2 = substr($kdtgl_akhir, 3, 2);
					$tgl2 = substr($kdtgl_akhir, 0, 2);
					$kdtgl_akhir = $tgl2 . '-' . $bln2 . '-' . $thn2;
					$bulan='DARI TANGGAL:' . $kdtgl_awal . ' s/d ' . $kdtgl_akhir;					
					$this->getActiveSheet()->setCellValue('A3',"$bulan");	


				}elseif ($kdtgl_awal = 'null' && $kdtgl_akhir = 'null') {
					$bulan='TANGGAL:  s/d ' .date('d-m-Y');					
					$this->getActiveSheet()->setCellValue('A3',"$bulan");

				}
			}			
		}else{
			//$bulan='TANGGAL:  s/d ' .date('d-m-Y');					
			//$this->getActiveSheet()->setCellValue('A2',"$bulan");

		}

			
		//-------------------------------------------
		//nama satker
		$kodenm_satker=$par_umum1['kodenm_satker'];
		if($kodenm_satker != 'null'){
			$d_kppn = new DataUser($this->registry);
			foreach ($d_kppn->get_d_user_kppn($kodenm_satker) as $nm_satker1) {
					$nm_satker = $nm_satker1->get_nama_user();
			} 
			if(strlen($kodenm_satker)==3){
				$kodenm_satker1=trim($nm_satker).' - '.trim($kodenm_satker);
				$this->getActiveSheet()->setCellValue('A3',"$kodenm_satker1");
			}elseif(strlen($kodenm_satker)==6){
				$kodenm_satker1='SATKER : '.trim($nm_satker).' - '.trim($kodenm_satker);
				$this->getActiveSheet()->setCellValue('A3',"$kodenm_satker1");
			}
	
		} 
		
 
			
		//------------------------------------------------------------------
		
	}
	 //footer
    function Footer($cxls,$judul1) {
		//$tipefile = 'xls';
		$tipefile = 'xlsx';
		
		//-----------------------  
		// Set page orientation and size
		$cxls->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
		$cxls->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL);
		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$cxls->setActiveSheetIndex(0);
		//-------------------------------------
		
		if($tipefile =='xls'){
			// Save as an Excel BIFF (xls) file
			// filename
			$filename = "Laporan " . $judul1 . ".xls";
			$objWriter = PHPExcel_IOFactory::createWriter($cxls, 'Excel5');
			header("Content-Type: application/vnd.ms-excel");
			
		}elseif($tipefile =='xlsx'){
			// Save Excel 2007 file
			// filename
			$filename = "Laporan " . $judul1 . ".xlsx";
			$objWriter = PHPExcel_IOFactory::createWriter($cxls, "Excel2007");
			$objWriter->setOffice2003Compatibility(true);
			header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
			
		}else{
			
		}
		
		//-------------------------
		// Redirect output to a client’s web browser 
		header("Pragma: no-cache");
		header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control: no-store, no-cache,must-revalidate");
		header("Cache-Control: pre-check=0, post-check=0, max-age=0");
		header("Content-Type: application/force-download");
		header("Content-Type: application/octet-stream");
		header("Content-Type: application/download");;
		header("Content-Transfer-Encoding: none");
		header("Content-Disposition: attachment; filename=\"$filename\"");		
		$objWriter->save('php://output');
		exit;

    }
	  
	
}


?>
